package design.mode.effective_java.chapter8.item50;


import java.util.Date;

/**
 * @author ZhongMingde on 2021/8/31
 */

public class Period {
    private final Date start;
    private final Date end;

    public Period(Date start, Date end) {

//        if (start.compareTo(end) > 0) {
//            throw new IllegalArgumentException(start + " after " + end);
//        }
//        this.start = start;
//        this.end = end;
        // 必须将每个可变参数的防御性副本复制给构造函数
        this.start = new Date(start.getTime());
        this.end = new Date(end.getTime());
        if (this.start.compareTo(end) > 0){
            throw new IllegalArgumentException(this.start + " after " + end);
        }
    }

    public Date start() {
//        return start;
        return new Date(start.getTime());
    }

    public Date end() {
        return new Date(end.getTime());
    }

    public static void main(String[] args) {
        Date start = new Date();
        Date end = new Date();
        Period p = new Period(start,end);
       //  end.setYear(78);
        p.end.setYear(78);
    }
}
